﻿
@{
    ViewData["Title"] = "RawmaterialtestingDetail";
    Layout = "~/Views/Home/Menu.cshtml";
}

<h1>原料编辑</h1>
<div style="width:1000px;border-color:black;border-style:solid;border-width:2px;margin:10px 20px;">
	<div class="layui-form-item" style="margin:10px 20px;">
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			原料编号:<span id="rawMaterialNumbering"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap">
			原料名称:<span id="rawMaterialName"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			原料分类:<span id="rawMaterialClassify"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap">
			尺寸:<span id="rawMaterialSize"></span>
		</div>
	</div>
	<div class="layui-form-item" style="margin:10px 20px;">
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			规格型号:<span id="rawMaterialSpecModel"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap">
			原料属性:<span id="rawMaterialAttribute"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			单位:<span id="rawMaterialUnit"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap">
			库存数量:<span id="rawMaterialinventory"></span>
		</div>
	</div>
	<div class="layui-form-item" style="margin:10px 20px;">
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			原料类型:<span id="rawMaterialType"></span> <a onclick="tiao()">发起采购</a>
		</div>
		<div class="layui-input-inline layui-input-wrap">
			状态:<span id="rawMaterilStatus"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap;line - spacing:500">
			原料数量:<span id="rawMaterialNumber"></span>
		</div>
		<div class="layui-inline">
			报警天数:提前<span id="rawMaterialDay"></span>天报警
		</div>
	</div>
	<div class="layui-form-item" style="margin:10px 20px;">
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			库存上限:<span id="inventoryMaximums"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap">
			库存下限:<span id="inentoryLower"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap;line - spacing:600">
			原料位置:<span id="rawMateriallocation"></span>
		</div>
		<div class="layui-input-inline layui-input-wrap">
			创建时间:<span id="rawMaterialDate"></span>
		</div>
	</div>
	<div class="layui-form-item layui-form-text" style="margin:10px 20px;">
		<div class="layui-input-block" style="width:600Px">
			备注:<span id="rawMaterialReamrk"></span>
		</div>
	</div>
</div>
<script>
	//文档就绪函数
	$(function () {
		fantian()
	})
	var obj = {
		rawMaterialId: 0,
		rawMaterialNumbering: "",
		rawMaterialName: "",
		rawMaterialClassify: "",
		rawMaterialSize: "",
		rawMaterialSpecModel: "",
		rawMaterialAttribute: "",
		rawMaterialUnit: "",
		rawMaterialinventory: 0,
		rawMaterialType: "",
		rawMaterilStatus: "",
		rawMaterialNumber: 0,
		rawMaterialDay: 0,
		inventoryMaximums: 0,
		inentoryLower: 0,
		rawMateriallocation: "",
		rawMaterialDate: "",
		rawMaterialReamrk: "",
		rawMaterialImage: "",
		addName: "",
		addTime: "",
	}
	function fantian() {
		return new Promise(function (resolve, reject) {
			$(document).ready(function () {
				// 获取要编辑的用户ID，可以通过URL参数或者其他方式获取，这里假设通过URL参数获取
				var rawMaterialId = localStorage.getItem("rawMaterialId");
				console.log(rawMaterialId);
				// 如果获取到了用户ID，就去后台获取该用户的详细信息并反填到表单
				if (rawMaterialId) {
					$.ajax({
						type: "get",
						url: "/RawMaterial/RawMaterMondel",
						data: {
							rawMaterialId: rawMaterialId
						},
						success: function (res) {
							var resse = JSON.parse(res)
							console.log(resse)
							if (resse.data) {
								const s = resse.data;
								//反填日期框
								var da = new Date(s.rawMaterialDate);
								// 获取年、月、日
								var year = da.getFullYear();
								var month = (da.getMonth() + 1).toString().padStart(2, '0');  // 月份从0开始，因此加1
								var day = da.getDate().toString().padStart(2, '0');  // 补充两位数字
								// 拼接成 "yyyy-MM-dd" 格式
								var formattedDate = `${year}-${month}-${day}`;
								console.log(formattedDate)
								$('#rawMaterialId').text(s.rawMaterialId);
								$('#rawMaterialNumbering').text(s.rawMaterialNumbering);
								$('#rawMaterialName').text(s.rawMaterialName);
								$('#rawMaterialClassify').text(s.rawMaterialClassify);
								layui.form.render('select')
								$('#rawMaterialSize').text(s.rawMaterialSize);
								layui.form.render('select')
								$('#rawMaterialSpecModel').text(s.rawMaterialSpecModel);
								layui.form.render('select')
								$('#rawMaterialAttribute').text(s.rawMaterialAttribute);
								layui.form.render('select')
								$('#rawMaterialUnit').text(s.rawMaterialUnit);
								layui.form.render('select')
								$('#rawMaterialinventory').text(s.rawMaterialinventory);
								$('#rawMaterialType').text(s.rawMaterialType);
								layui.form.render('select')
								$('#rawMaterilStatus').text(s.rawMaterilStatus);
								//是否禁用
								var lswarehouseState = s.rawMaterilStatus
								$("[name='rawMaterilStatus']").each(function () {
									if (lswarehouseState.toString() == $(this).text()) {
										$(this).prop("checked", true);
									}
								})
								$('#rawMaterialNumber').text(s.rawMaterialNumber);
								$('#rawMaterialDay').text(s.rawMaterialDay);
								$('#inventoryMaximums').text(s.inventoryMaximums);
								$('#inentoryLower').text(s.inentoryLower);
								$('#rawMateriallocation').text(s.rawMateriallocation);
								$('#rawMaterialDate').text(formattedDate);
								$('#rawMaterialReamrk').text(s.rawMaterialReamrk);
								$('#rawMaterialImage').text(s.rawMaterialImage);
								$('#addName').text(s.addName);
								$('#addTime').text(s.addTime);
								obj.rawMaterialId = s.rawMaterialId
							}
						}
					})
				}
			});
		});
	};
	
	function tiao(){
		var rawMaterialId = localStorage.getItem("rawMaterialId")
		localStorage['rawMaterialId'] = rawMaterialId;
		console.log(rawMaterialId)
		location.href = '/RawMaterial/ProcuredAdd';
	}
</script>
<script src="~/js/rawmaterialcontroller1/rawmaterialjs.js"></script>